<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>catch</title>
  </head>
  <body>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
      axios.defaults.baseURL = "http://localhost:9000";
      axios.defaults.headers.post["Content-Type"] =
        "application/json;charset=UTF-8";
      axios.interceptors.request.use(
        (config) => {
          let access_token = sessionStorage.getItem("access_token"); // 在发送请求前把sessionStorage中的token写到请求头里
          config.headers = {
            Authorization: `Bearer ${access_token}`,
          };
          return config;
        },
        (error) => {
          return Promise.reject(error);
        }
      );

      axios.interceptors.response.use(
        (response) => {
          return response.data;
        },
        (error) => {
          (async () => {
            try {
              await Promise.reject("1234");
            } catch (ex) {
              debugger;
            }
          })();
          return Promise.reject(error);
        }
      );

      axios.post("http://locahost:3000");
    </script>
    <script>
      (async () => {
        try {
          await Promise.reject("1234");
        } catch (ex) {}
      })();
    </script>
  </body>
</html>
